# Maintainer: Carlo Landmeter <clandmeter@gmail.com>
# Contributor: Łukasz Jendrysik <scadu@yandex.com>
pkgname=sqlite-tcl
pkgver=3.33.0
pkgrel=0
pkgdesc="Sqlite Tcl Extension Architecture (TEA)"
url="https://www.sqlite.org/"
arch="all"
license="Public-Domain"
makedepends="readline-dev tcl-dev sqlite-dev libtool autoconf automake"
subpackages="$pkgname-doc"
options="!check" # no testsuite from upstream

# compute _ver
_a=${pkgver%%.*}
_b=${pkgver#$_a.}
_b=${_b%%.*}
_c=${pkgver#$_a.$_b.}
_c=${_c%%.*}
case $pkgver in
	*.*.*.*)_d=${pkgver##*.};;
	*.*.*)	_d=0;;
esac
[ $_b -lt 10 ] && _b=0$_b
[ $_c -lt 10 ] && _c=0$_c
[ $_d -lt 10 ] && _d=0$_d
_ver=${_a}${_b}${_c}$_d

# these variables depend on _ver being set
source="https://www.sqlite.org/2020/sqlite-autoconf-$_ver.tar.gz"
builddir="$srcdir/sqlite-autoconf-$_ver/tea"

prepare() {
	default_prepare

	if [ -f "$startdir"/../sqlite/APKBUILD ]; then
		(
		_tclver=$pkgver
		. "$startdir"/../sqlite/APKBUILD
		if [ "$_tclver" != "$pkgver" ]; then
			die "sqlite version mismatch ($_tclver != $pkgver)"
		fi
		)
	fi
}

build() {
	./configure \
		--build="$CBUILD" \
		--host="$CHOST" \
		--prefix=/usr \
		--with-system-sqlite \
		--enable-threads
	make
}

check() {
	make check
}

package() {
	make DESTDIR="$pkgdir" install
	install -Dm644 license.terms \
		"$pkgdir"/usr/share/licenses/$pkgname/license.terms
}

sha512sums="c0d79d4012a01f12128ab5044b887576a130663245b85befcc0ab82ad3a315dd1e7f54b6301f842410c9c21b73237432c44a1d7c2fe0e0709435fec1f1a20a11  sqlite-autoconf-3330000.tar.gz"
